package com.example.nonacademic_education.util.timer;

import com.example.nonacademic_education.constant.KapchaCode;
import com.example.nonacademic_education.constant.SingleFactory;
import com.example.nonacademic_education.dao.DepartmentDao;
import com.example.nonacademic_education.data.sys.Login;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.Map;

/**
 * @author xinmiao
 * @description
 * @date 2023/3/26 17:01
 */
public class CodesClearJob implements Job {

    @Resource
    private KapchaCode kapchaCode;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        Iterator<Map.Entry<String, Long>> iterator = kapchaCode.getCodes().entrySet().iterator();
        long nowTime=System.currentTimeMillis();
        while (iterator.hasNext()) {
            Map.Entry<String, Long> entry = iterator.next();
            if (entry.getValue()-nowTime>1800000) {
                iterator.remove(); // 删除符合条件的元素
            }
        }
        Iterator<Map.Entry<String, Login>> iterator2 = SingleFactory.getInstance().getLogins().entrySet().iterator();
        while (iterator2.hasNext()) {
            Map.Entry<String, Login> entry = iterator2.next();
            if (entry.getValue().getCnt()==-1) {
                iterator.remove(); // 删除符合条件的元素
            }
        }
    }
}
